#include <iostream>
#include <unistd.h>

int main()
{
    pid_t id = fork();
    if (id == 0)
    {
        static int count = 0;
        while (true)
        {
            // 子进程
            std::cout << "子进程创建：" << getpid() << " ppid: " << getppid() << std::endl;
            sleep(1);
            if (++count == 30)
                break;
        }
    }
    else if (id > 0)
    {
        while (true)
        {
            std::cout << "父进程创建：" << getpid() << " ppid: " << getppid() << std::endl;
            sleep(1);
        }
    }
    else
    {
        std::cout << "fork() error " << std::endl;
    }
    return 0;
}